﻿/**
as3app - An open-source ActionScript 3.0 Library developed to assist 
in creating simple visual controls/data binding/asset loading for the
Flash player platform.

http://code.google.com/p/as3app/

Copyright (c) 2011 M. K. Chowdhury, All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package as3app.visuals
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Rectangle;
	import flash.events.Event;
	import flash.utils.Timer;
	
	
	/**
	 * @author
	 * Muntasir Kabir Chowdhury
	 * 
	 * @example
	 * 
	 */
	public class SimpleScrollBar extends Sprite 
	{
		
		public static const SCROLL_VERTICAL:int = 0;
		public static const SCROLL_HORIZONTAL:int = 1;
		public static const SCROLL_BOTH:int = 2; 
		
		
		
		
		
		
		protected var _scrollTimer:Timer = new Timer(50, 0);
		protected var _backgroundSprite:Sprite = new Sprite();
		
		
		
		
		
		
		protected var _scrollType:int = SCROLL_BOTH;
		public function get ScrollType():int { return _scrollType; }
		public function set ScrollType(scrollType:int) 
		{ 
			_scrollType = scrollType; 
			updateMask();
			Update();
		}
		
		
		
		
		
		
		
		
		protected var _showVScrollBar:Boolean = false;
		public function get showVScrollBar():Boolean { return _showVScrollBar; }
		public function set showVScrollBar(val:Boolean):void 
		{
			_showVScrollBar = val; 
			updateMask();
			Update();
		}
		
		
		
		
		
		
		
		
		protected var _showHScrollBar:Boolean = false;
		public function get showHScrollBar():Boolean { return _showHScrollBar; }
		public function set showHScrollBar(val:Boolean):void 
		{
			_showHScrollBar = val; 
			
			redrawHorizontalTrackBar();
			redrawHorizontalTrackTick();
			redrawVertiacalTrackBar();
			redrawVerticalTrackTick();
		}
		
		
		
		
		
		
		
		protected var _maxHeight:Number;
		public function get MaxHeight():Number { return _maxHeight; }
		public function set MaxHeight(maxHeight:Number)
		{
			_maxHeight = maxHeight;
			updateMask();
			Update();
		}
		
		
		
		
		
		
		
		
		protected var _maxWidth:Number;
		public function get MaxWidth():Number { return _maxWidth; }
		public function set MaxWidth(maxWidth:Number)
		{
			_maxWidth = maxWidth;
			updateMask();
			Update();
		}
		
		
		
		
		
		
		
		
		
		
		protected var _extraScrolling:Number = 0;
		public function get ExtraScrolling():Number { return _extraScrolling; }
		public function set ExtraScrolling(extraScrolling:Number)
		{
			_extraScrolling = extraScrolling;
			redrawHorizontalTrackTick();
			redrawVerticalTrackTick();
		}
		
		
		
		
		
		
		
		
		
		
		
		
		protected var _backgroundColor:Array = [0xFFFFFF, 0];
		public function get BackgroundColor():Array { return _backgroundColor; }
		public function set BackgroundColor(backgroundColor:Array)
		{
			_backgroundColor = backgroundColor;
			redrawBackground();
			
		}
		
		
		
		
		
		
		
		
		protected function redrawBackground():void
		{
			var shape:Shape = new Shape();
			shape.graphics.beginFill(_backgroundColor[0], _backgroundColor[1]);
			shape.graphics.drawRect(0, 0, _maxWidth, _maxHeight);
			shape.graphics.endFill();
			
			while (_backgroundSprite.numChildren > 0) _backgroundSprite.removeChildAt(0);
			_backgroundSprite.addChild(shape);
		}
		
		
		
		
		
		
		
		protected var _target:DisplayObject;
		
		
		
		
		
		
		
		
		
		protected var _trackBarWidth:Number = 12;
		public function get TrackBarWidth():Number { return _maxWidth; }
		public function set TrackBarWidth(trackBarWidth:Number)
		{
			_trackBarWidth = trackBarWidth;
			redrawVertiacalTrackBar();
			redrawHorizontalTrackBar();
			updateMask();
		}

		
		
		
		
		
		
		
		
		
		
		protected var _tickBarWidthDifference:Number = 2;
		public function get TickBarWidthDifference():Number { return _tickBarWidthDifference; }
		public function set TickBarWidthDifference(tickBarWidthDifference:Number)
		{
			_tickBarWidthDifference = tickBarWidthDifference;
			redrawHorizontalTrackTick();
			redrawVerticalTrackTick();
		}
		
		
		
		
		
		
		
		
		
		
		protected var _horizontalBarAsset:DisplayObject = null;
		public function get HorizontalBarAsset():DisplayObject { return _horizontalBarAsset; }
		public function set HorizontalBarAsset(horizontalBarAsset:DisplayObject) { _horizontalBarAsset = horizontalBarAsset; redrawHorizontalTrackBar(); }
		
		
		
		
		
		
		
		
		
		
		protected var _verticalBarAsset:DisplayObject = null;
		public function get VerticalBarAsset():DisplayObject { return _verticalBarAsset; }
		public function set VerticalBarAsset(verticalBarAsset:DisplayObject) { _verticalBarAsset = verticalBarAsset; redrawVertiacalTrackBar(); }
		
		
				
		
		
		
		
		
		
		
		
		
		protected var _horizontalTickAsset:DisplayObject = null;
		public function get HorizontalTickAsset():DisplayObject { return _horizontalTickAsset; }
		public function set HorizontalTickAsset(horizontalTickAsset:DisplayObject) { _horizontalTickAsset = horizontalTickAsset; redrawHorizontalTrackTick(); }
		
				
		
		
		
		
		
		
		
		
		
		protected var _verticalTickAsset:DisplayObject = null;
		public function get VerticalTickAsset():DisplayObject { return _verticalTickAsset; }
		public function set VerticalTickAsset(verticalTickAsset:DisplayObject) { _verticalTickAsset = verticalTickAsset; redrawVerticalTrackTick(); }
		
				
		
		
		
		
		
		
		
		
		
		protected var barColors:Array = [0xA1A59E, 0xB1B5CE];
		public function set BarColors(colors:Array):void { barColors = colors; updateMask(); }
		
		
				
		
		
		
		
		
		
		
		
		
		protected var barAlphas:Array = [.5, 1];
		public function set BarAlthas(alphas:Array):void { barAlphas = alphas; updateMask(); }
				
		
		
		
		
		
		
		
		
		
		protected var barRatios:Array = [13, 5];
		public function set BarRatios(ratios:Array):void { barRatios = ratios; updateMask();}
		
				
		
		
		
		
		
		
		
		
		
		protected var barPickColors:Array = [0xFFDFDF, 0xFFDFDF];
		public function set BarPickColors(picColors:Array):void { barPickColors = picColors; updateMask();}
				
		
		
		
		
		
		
		
		
		
		protected var barPickAlphas:Array = [.7, .9];
		public function set BarPickAlphas(pickAlphas:Array):void { barPickAlphas = pickAlphas; updateMask();}
				
		
		
		
		
		
		
		
		
		
		protected var barPickRatios:Array = [13, 5];
		public function set BarPickRatios(pickRatios:Array):void { barPickRatios = pickRatios; updateMask();}
		
		
		
		
		
		
		
		
		
		
		protected function On_MouseWheelMove(e:MouseEvent)
		{
			if (e.delta != 0)
			{
				ScrollY -= 0.01 * e.delta;
			}
		}
		
		
		
		
		
		
		
		
		
		
		public function SimpleScrollBar(targetDisplayObject:DisplayObject, maxHeight:Number=-1, maxWidth:Number=-1)
		{
			_target = targetDisplayObject;
			
			
			this.addEventListener(MouseEvent.MOUSE_WHEEL, On_MouseWheelMove);
			
			
			if (maxHeight < 0 || maxWidth < 0)
			{
				_maxWidth = _target.width;
				_maxHeight = _target.height;
			}
			else 
			{
				_maxHeight = maxHeight;
				_maxWidth = maxWidth;
			}
			
			_scrollX = 0;
			_scrollY = 0;
			
			addChild(_backgroundSprite);
			addChild(_target);
			addChild(_borderSprite);
			addChild(_horizontalTrackBar);
			addChild(_horizintalTrackTick);
			addChild(_verticalTrackBar);
			addChild(_verticalTrackTick);
			_verticalTrackTick.buttonMode = true;
			
			
			_verticalTrackTick.addEventListener(MouseEvent.MOUSE_DOWN, On_VerticalTick_MouseDown );
			_verticalTrackTick.addEventListener(MouseEvent.MOUSE_UP, On_VerticalTick_MouseUp );
			//_verticalTrackTick.addEventListener(MouseEvent.MOUSE_OUT, On_VerticalTick_MouseUp );

			
			_horizintalTrackTick.addEventListener(MouseEvent.MOUSE_DOWN, On_HorizontalTick_MouseDown );
			_horizintalTrackTick.addEventListener(MouseEvent.MOUSE_UP, On_HorizontalTick_MouseUp );
			//_horizintalTrackTick.addEventListener(MouseEvent.MOUSE_OUT, On_HorizontalTick_MouseUp );
			
			updateMask();
			Update();
		}
		
		
		
		
		
		
		
		
		
		
		protected var _isDragging:Boolean = false;
		
		
		
		
		
		
		
		
		
		
		protected var _mask:DisplayObject = null;
		protected function updateMask()
		{
			if (_mask != null) removeChild(_mask);
			
			var rect:Shape = new Shape();
			rect.graphics.beginFill(0xFFFFFF, 0); 
			rect.graphics.drawRect(0, 0, _maxWidth, _maxHeight);
			rect.graphics.endFill();
			_mask = rect;
			
			addChild(_mask);
			_target.mask = _mask;
			
			_verticalTrackBar.x = _maxWidth;
			_verticalTrackBar.y = 0;
			
			_horizontalTrackBar.x = 0;
			_horizontalTrackBar.y = _maxHeight;
			
			_verticalTrackTick.x = _maxWidth;
			_verticalTrackTick.y = 0;
			
			_horizintalTrackTick.x = 0;
			_horizintalTrackTick.y = _maxHeight;
			
			redrawBorder();
			redrawHorizontalTrackBar(); 
			redrawVertiacalTrackBar();
			
			if(_target.width>_maxWidth) redrawHorizontalTrackTick();
			if(_target.height>_maxHeight) redrawVerticalTrackTick();
		}
		
		
		
		
		
		
		
		
		
		
		protected var _borderLineStyle:Array = [2, 0x559966, 1];
		public function borderLineStyle(thickness:Number = 2, color:uint = 0x559966, alpha:Number = 1):void 
		{
			_borderLineStyle = [thickness, color, alpha]; 
			updateMask();
		}
		
		
		
		
		
		
		
		
		
				protected var _borderSprite:Sprite = new Sprite();
		protected function redrawBorder()
		{
			var shape:Shape = new Shape();
			shape.graphics.lineStyle(_borderLineStyle[0], _borderLineStyle[1], _borderLineStyle[2]);
			shape.graphics.drawRect(0, 0, _maxWidth + _trackBarWidth, _maxHeight);
			
			while (_borderSprite.numChildren > 0) _borderSprite.removeChildAt(0);
			_borderSprite.addChild(shape);
			_borderSprite.mouseChildren = false;
			_borderSprite.mouseEnabled = false;
		}
		
		
		
		
		
		
		
		
		
		
		protected var _scrollY:Number = 0;
		public function get ScrollY():Number { return _scrollY; }
		public function set ScrollY(scrollY:Number) 
		{ 
			if (scrollY >= 0 && scrollY <= 1 && (_scrollType==0 || _scrollType==2) && _target.height>_maxWidth)
			{
				_scrollY = scrollY;
				_target.y = -(_scrollY * (_target.height - _maxHeight));
				_verticalTrackTick.y = _scrollY * (_maxHeight - _verticalTrackTick.height);
			}
		}
		
		
		
		
		
		
		
		
		
		
		protected var _verticalTrackBar:Sprite = new Sprite();
		public function redrawVertiacalTrackBar()
		{
			
			if (_verticalBarAsset == null)
			{
				var rect:Shape = new Shape();
				rect.graphics.beginGradientFill("linear", barColors, barAlphas, barRatios); 
				rect.graphics.drawRect(0, 0, _trackBarWidth, _maxHeight);
				rect.graphics.endFill();
				
				
				while (_verticalTrackBar.numChildren > 0) _verticalTrackBar.removeChildAt(0);
				_verticalTrackBar.addChild(rect);
				
				_verticalTrackBar.x = _maxWidth;
			}
			else
			{
				_verticalBarAsset.width = _trackBarWidth;
				_verticalBarAsset.height = _maxHeight;
				
				while (_verticalTrackBar.numChildren > 0) _verticalTrackBar.removeChildAt(0);
				_verticalTrackBar.addChild(_verticalBarAsset);
			}
		}
		
		
		
		
		
		
		
		
		
		
		protected var _verticalTrackTick:Sprite = new Sprite();
		protected function redrawVerticalTrackTick()
		{
			var afftecedHeight:Number = _target.height + _extraScrolling;
			if (_verticalTickAsset == null)
			{
				var rect:Shape = new Shape();
				rect.graphics.beginGradientFill("linear", barPickColors, barPickAlphas, barPickRatios); 
				if (afftecedHeight <= _maxHeight) 
				{
					if (_showVScrollBar) rect.graphics.drawRect(_tickBarWidthDifference, 0, _trackBarWidth - _tickBarWidthDifference-_tickBarWidthDifference, Number(_maxHeight * _maxHeight / (_maxHeight + _extraScrolling)));
				}
				else rect.graphics.drawRect(_tickBarWidthDifference, 0, _trackBarWidth - _tickBarWidthDifference-_tickBarWidthDifference, _maxHeight * _maxHeight / afftecedHeight);
				rect.graphics.endFill();
				
				
				while (_verticalTrackTick.numChildren > 0) _verticalTrackTick.removeChildAt(0);
				_verticalTrackTick.addChild(rect);	
			}
			else 
			{
				_verticalTickAsset.width = _trackBarWidth - _tickBarWidthDifference-_tickBarWidthDifference;
				_verticalTickAsset.x = _tickBarWidthDifference;
				_verticalTickAsset.y = 0;
				if (afftecedHeight <= _maxWidth) 
				{
					if (_showVScrollBar) 
					{							
						_verticalTickAsset.height = Number(_maxHeight * _maxHeight / (_maxHeight + _extraScrolling));
						_verticalTickAsset.visible = true;
					}

				}
				else 
				{
					_verticalTickAsset.height = Number(_maxHeight * _maxHeight / afftecedHeight);
					_verticalTickAsset.visible = true;
				}
				
				while (_verticalTrackTick.numChildren > 0) _verticalTrackTick.removeChildAt(0);
				_verticalTrackTick.addChild(_verticalTickAsset);	
			}
		}
		
		
		
		
		
		
		
		
		
		
		protected var _scrollX:Number = 0;
		protected function get ScrollX():int { return _scrollX; }
		protected function set ScrollX(scrollX:int) 
		{ 
			if (scrollX >= 0 && scrollX <= 1)
			{
				_scrollX = scrollX;
				_horizintalTrackTick.x = _scrollX * _maxWidth;
			}
		}
		
		
		
		
		
		
		
		
		
		
		protected var _horizontalTickPath:Rectangle;
		protected var _horizontalTrackBar:Sprite = new Sprite();
		public function redrawHorizontalTrackBar()
		{
			_horizontalTrackBar.x = 0;
			_horizontalTrackBar.y = _maxHeight;
			
			if (_horizontalBarAsset == null)
			{
				var rect:Shape = new Shape();
				rect.graphics.beginGradientFill("linear", barColors, barAlphas, barRatios); 
				rect.graphics.drawRect(0, 0, _maxWidth, _trackBarWidth);
				rect.graphics.endFill();
				
				
				while (_horizontalTrackBar.numChildren > 0) _horizontalTrackBar.removeChildAt(0);
				_horizontalTrackBar.addChild(rect);
				
			}
			else
			{
				_horizontalBarAsset.width = _maxWidth;
				_horizontalBarAsset.height = _trackBarWidth;
				
				while (_horizontalTrackBar.numChildren > 0) _horizontalTrackBar.removeChildAt(0);
				_horizontalTrackBar.addChild(_horizontalBarAsset);
			}
		}
		
		
		
		
		
		
		
		
		
		
		protected var _horizintalTrackTick:Sprite = new Sprite();
		public function redrawHorizontalTrackTick()
		{
			var afftecedWidth:Number = _target.width + _extraScrolling;
			
			if (_verticalTickAsset == null)
			{
				var rect:Shape = new Shape();
				rect.graphics.beginGradientFill("linear", barPickColors, barPickAlphas, barPickRatios); 
				if (afftecedWidth <= _maxWidth) 
				{
					if (_showVScrollBar) rect.graphics.drawRect(_tickBarWidthDifference, 0, Number(_maxWidth * _maxWidth / (_maxWidth + _extraScrolling)), _trackBarWidth - _tickBarWidthDifference-_tickBarWidthDifference);
				}
				else rect.graphics.drawRect(_tickBarWidthDifference, 0, _maxWidth * _maxWidth / afftecedWidth, _trackBarWidth - _tickBarWidthDifference-_tickBarWidthDifference);
				rect.graphics.endFill();
				
				
				while (_horizintalTrackTick.numChildren > 0) _horizintalTrackTick.removeChildAt(0);
				_horizintalTrackTick.addChild(rect);	
			}
			else 
			{
				_horizontalTickAsset.height = _trackBarWidth - _tickBarWidthDifference-_tickBarWidthDifference;
				_horizontalTickAsset.y = _tickBarWidthDifference;
				_horizontalTickAsset.x = 0;
				if (afftecedWidth <= _maxWidth) 
				{
					if (_showHScrollBar) 
					{							
						_horizontalTickAsset.width = Number(_maxWidth * _maxWidth / (_maxWidth + _extraScrolling));
						_horizontalTickAsset.visible = true;
					}
					else _horizontalTickAsset.visible = false;
				}
				else 
				{
					_horizontalTickAsset.width = Number(_maxWidth * _maxWidth / afftecedWidth);
					_horizontalTickAsset.visible = true;
				}
				
				while (_verticalTrackTick.numChildren > 0) _verticalTrackTick.removeChildAt(0);
				_verticalTrackTick.addChild(_horizontalTickAsset);	
			}
		}
		
		
		
		
		
		
		
		
		
		
		protected var lastKnowenWidth:Number = -1;
		protected var lastKnowenHeight:Number = -1;
		
		public function Update(currentTargerHeight:Number = -1, currentTargerWidth:Number = -1)
		{
			if (currentTargerHeight < 0 || currentTargerWidth < 0)
			{
				currentTargerWidth = _target.width;
				currentTargerHeight = _target.height;
			}
			
			currentTargerHeight += _extraScrolling;
			currentTargerWidth += _extraScrolling;

			if (_scrollType == 0 || _scrollType == 2)
			{
				lastKnowenHeight = currentTargerHeight;
				_verticalTrackTick.visible = currentTargerHeight > _maxHeight || _showVScrollBar;
				_verticalTrackBar.visible = _verticalTrackTick.visible;
				redrawVerticalTrackTick();
				_scrollY = -(_target.y / currentTargerHeight);
				_scrollY = _scrollY > 1 || _scrollY < 0?0:_scrollY;	
				_verticalTrackTick.y = (_maxHeight - _verticalTrackTick.height) * _scrollY;
			}
			else 
			{
				if (_showVScrollBar) 
				{
					redrawVerticalTrackTick();
					_verticalTrackTick.y = 0;
					_scrollY = 0;
				}
				// Hide or show vertical scrolling.
				_verticalTrackBar.visible = _showVScrollBar;
				_verticalTrackTick.visible = _showVScrollBar;
			}
			_target.y = 0;
			
			
			if (_scrollType == 1 || _scrollType == 2)
			{
				lastKnowenWidth = currentTargerWidth;
				_horizintalTrackTick.visible = currentTargerWidth > _maxWidth || _showHScrollBar;
				_horizontalTrackBar.visible = _horizintalTrackTick.visible;
				
				redrawHorizontalTrackTick();
				_scrollX = -(_target.x / currentTargerWidth);
				_scrollX = _scrollX > 1 || _scrollX < 0?0:_scrollX;	
				_horizintalTrackTick.x = (_maxWidth - _horizintalTrackTick.width) * _scrollX;
			}
			else 
			{
				if (_showHScrollBar) 
				{
					redrawHorizontalTrackTick();
					_verticalTrackTick.y = 0;
					_scrollY = 0;
				}
				// Hide or show vertical scrolling.
				_horizontalTrackBar.visible = _showHScrollBar;
				_horizintalTrackTick.visible = _showHScrollBar;
			}
			_target.x = 0;
			
		}
		
		
		
		
		
		
		
		
		
		
		protected function On_VerticalTick_MouseDown(e:MouseEvent)
		{
			//if (!_verticalTrackTick.hasEventListener(MouseEvent.MOUSE_MOVE)) _verticalTrackTick.addEventListener(MouseEvent.MOUSE_MOVE, On_VerticalTick_MouseMove);	
			if (!_scrollTimer.hasEventListener(TimerEvent.TIMER)) 
			{
				_scrollTimer.addEventListener(TimerEvent.TIMER, On_VerticalScroolTimerEvent);
				_scrollTimer.start();
			}
			
			var rect:Rectangle = _verticalTrackBar.getRect(this);
			rect.width = .01;
			rect.height -= _verticalTrackTick.height;
			_verticalTrackTick.startDrag(false,rect);
		}
		
		
		
		
		
		
		
		
		
		
		protected function On_VerticalTick_MouseUp(e:MouseEvent)
		{
			if (_scrollTimer.hasEventListener(TimerEvent.TIMER)) _scrollTimer.removeEventListener(TimerEvent.TIMER, On_VerticalScroolTimerEvent);
			if(_scrollTimer.running) _scrollTimer.stop();
			
			//if (_verticalTrackTick.hasEventListener(MouseEvent.MOUSE_MOVE)) _verticalTrackTick.removeEventListener(MouseEvent.MOUSE_MOVE, On_VerticalTick_MouseMove);	
			_verticalTrackTick.stopDrag();
		}
		
		
		
		
		
		
		
		
		
		
		protected function On_VerticalScroolTimerEvent(evt:Event)
		{
			_scrollY = _verticalTrackTick.y / (_maxHeight - _verticalTrackTick.height);
			_target.y = -(_scrollY * ((_target.height + _extraScrolling <= _maxHeight?Number(_maxHeight + _extraScrolling):Number(_target.height + _extraScrolling)) - _maxHeight));
		}
		
		
		
		
		
		
		
		
		
		
		protected function On_HorizontalTick_MouseDown(e:MouseEvent)
		{
			if (!_scrollTimer.hasEventListener(TimerEvent.TIMER)) 
			{
				_scrollTimer.addEventListener(TimerEvent.TIMER, On_HorizontalScroolTimerEvent);
				_scrollTimer.start();
			}
			
			var rect:Rectangle = _horizontalTrackBar.getRect(this);
			rect.height = .01;
			rect.width -= _horizintalTrackTick.width;
			_horizintalTrackTick.startDrag(false, rect);
			
		}
		
		
		
		
		
		
		
		
		
		
		protected function On_HorizontalTick_MouseUp(e:MouseEvent)
		{
			if (_scrollTimer.hasEventListener(TimerEvent.TIMER)) _scrollTimer.removeEventListener(TimerEvent.TIMER, On_HorizontalScroolTimerEvent);
			if(_scrollTimer.running) _scrollTimer.stop();
			
			//if (_verticalTrackTick.hasEventListener(MouseEvent.MOUSE_MOVE)) _verticalTrackTick.removeEventListener(MouseEvent.MOUSE_MOVE, On_VerticalTick_MouseMove);	
			_horizintalTrackTick.stopDrag();
		}
		
		
		
		
		
		
		
		
		
		
		protected function On_HorizontalScroolTimerEvent(evt:Event)
		{
			_scrollX = _horizintalTrackTick.x / (_maxWidth - _horizintalTrackTick.height);
			_target.x = -(_scrollX * ((_target.width + _extraScrolling <= _maxWidth?Number(_maxWidth + _extraScrolling):Number(_target.width + _extraScrolling)) - _maxWidth));
		}
		
		
		
		
		
		
		
		
		
		
		public  function ShowAt(xLoc:Number, yLoc:Number)
		{
			if (_scrollType == 0 || _scrollType == 2)
			{
				if (_target.height - yLoc >= _maxHeight)
				{
					ScrollY = yLoc / (_target.height - _maxHeight);
				}
				else ScrollY = 1;
			}
		}
		
		
	}
}